import Vue from 'vue'
import App from './App.vue'
import './registerServiceWorker'
import router from './router'
import store from './store'
import axios from 'axios'
import VueAxios from 'vue-axios'
import Vant from 'vant'
import moment from 'moment'
import VueWechatTitle from 'vue-wechat-title'
import 'amfe-flexible'
import 'vant/lib/index.css'
import '@/assets/css/resetui.css'
import '@/assets/css/reset.css'
import notoken from './utils/notoken.js'
import axio from './utils/request.js'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);
// 时间戳过滤器
import * as custom from '@/utils/filters'
Object.keys(custom).forEach(key => { Vue.filter(key, custom[key]) })
Vue.prototype.$notoken = notoken
Vue.prototype.img = 'http://freeze.ganmiaoedu.com/upload/'
Vue.config.productionTip = false
Vue.use(Vant);
Vue.use(VueAxios, axios)
Vue.use(VueWechatTitle)
Vue.prototype.$axios = axio
Vue.prototype.$moment = moment
Vue.prototype.$imageBase64 = (url) => {
  const img = new Image()
  //因为是网络资源所以会有图片跨域问题产生，此属性可以解决跨域问题，下文详解
  img.setAttribute("crossOrigin", 'anonymous');
  img.src = url;
  return new Promise((resolve, reject) => {
    img.onload = () => {
      //canvas基本配置
      const canvas = document.createElement("canvas");
      canvas.width = img.width;
      canvas.height = img.height;
      const ctx = canvas.getContext("2d");
      ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
      resolve({
        success: true,
        //canvas.toDataURL的方法将图片的绝对路径转换为base64编码
        base64: canvas.toDataURL()
      })
    }
    img.onerror = () => {
      reject({ success: false })
    }
  })
}
router.afterEach(() => {
  window.scrollTo(0, 0);
  // 或
  // window.scroll(0, 0);
});
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

